package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;

@Getter
@Setter
public class Commodity extends BaseDomain{
    public static final Integer STATE_LOWER =1;     // 已下架
    public static final Integer STATE_SHORTAGE =2;   // 缺货中
    public static final Integer STATE_UPPER = 3;     // 售卖中

    public static final Integer KIND_BOOK =1;                //书籍类
    public static final Integer KIND_CLOTHES =2;             // 衣服类
    public static final Integer KIND_EAT =3;                // 食品类
    public static final Integer KIND_INTELLIGENCE =4;      // 智能科技类
    public static final Integer KIND_UNDEFINED =5;          // 未定义类
    //名字
    private String name;
    //图片
    private String coverUrl;
    //种类
    private int kind;
    //购买需要的积分
    private int mark;
    //价格
    private int price;
    //状态
    private int state=STATE_SHORTAGE;//默认是缺货的
    //用户
    private User user;

    public String getJson() {
        HashMap<String, Object> map = new HashMap();
        map.put("id", id);
        map.put("name", name);
        map.put("coverUrl", coverUrl);
        map.put("kind", kind);
        map.put("mark", mark);
        map.put("price", price);
        map.put("state", state);
        return JSON.toJSONString(map);
    }

    //处理商品状态的
    public String getStateName() {
        String stateName;
        if (state == STATE_UPPER) {
            stateName = "售卖中";
        } else if(state == STATE_LOWER) {
            stateName = "已下架";
        }else{
            stateName = "缺货中";
        }
        return stateName;
    }
    //处理商品种类的
    public String getKindName() {
        String temp = "";
        switch(kind) {
            case 1:
                temp = "书籍类";
                break;
            case 2:
                temp = "衣服类";
                break;
            case 3:
                temp = "食品类";
                break;
            case 4:
                temp = "智能类";
                break;
            default:
                temp = "未定义类";
        }
        return temp;
    }

}